package main

import (
	"fmt"
	"net"

	"gitee.com/k-ayaka/et-userserver/api"
	"gitee.com/k-ayaka/et-userserver/config"
	"gitee.com/k-ayaka/et-userserver/service"

	"gitee.com/k-ayaka/std-go/dao"
	"gitee.com/k-ayaka/std-go/redis"
	"google.golang.org/grpc"
)

var port = 8001

func main() {
	// 初始化数据库连接
	dao.Init(dao.MYSQL, config.MySQL_URL(config.MYSQL_ONLINE))
	defer dao.Close()

	// 初始化Redis
	redis.Connect(&config.REDIS_ONLINE)
	defer redis.Close()

	// 开启RPC服务
	conn, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
	if err != nil {
		fmt.Printf("监听%d异常\n", port)
		return
	}
	defer conn.Close()
	server := grpc.NewServer()
	api.RegisterUserServiceServer(server, &service.UserService{})
	fmt.Printf("开始监听%d...\n", port)
	server.Serve(conn)
}
